#include <vector>
#include <set>
#include <iostream>

using namespace std;

// set + vector
class Intersect{
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
		// set 
		set<int> record;
		for(int i = 0; i < nums1.size(); i++)
			record.insert(nums1[i]);       
		// vector
		vector<int> result;
		for(int i = 0; i < nums2.size(); ++i){
			// 集合中存在某元素
			if(record.find(nums2[i]) != record.end()){
				result.push_back(nums2[i]);
				record.erase(nums2[i]);	
			}
				
		}
		
		return result;
    }
};
